<template>
    <div class="member-add">
        <div class="member-add-card">
            <Card>
                <p slot="title">
                    <a><Icon type="gear-a"></Icon> 会员卡发放</a>
                </p>
                <div class="formCon">
                    <a class="title">{{title}}</a>
                    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                        <FormItem label="用户编号" prop="username">
                            <Input v-model="formValidate.username" placeholder="请输入用户编号"></Input>
                        </FormItem>
                        <!--<FormItem label="手机号" prop="phone">-->
                        <!--<Input v-model="formValidate.phone" placeholder="请输入用户手机号"></Input>-->
                        <!--</FormItem>-->
                        <FormItem label="级别" prop="level">
                            <RadioGroup v-model="formValidate.level">
                                <Radio label="1">vip会员</Radio>
                                <Radio label="2">金卡会员</Radio>
                                <Radio label="3">钻石会员</Radio>
                                <Radio label="4">红钻会员</Radio>
                                <Radio label="5">皇钻会员</Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="数量" prop="num">
                            <Input v-model="formValidate.num" placeholder="请输入数量"></Input>
                        </FormItem>
                    </Form>
                    <div class="button_style">
                        <Button type="primary" @click="sub" :loading="loading">提交</Button>
                    </div>
                </div>
            </Card>
            <!--提交-->
            <!--<div class="subCon">-->
                <!--<ButtonGroup>-->
                   <!---->
                    <!--&lt;!&ndash;<Button type="ghost" @click="reset">重置</Button>&ndash;&gt;-->
                <!--</ButtonGroup>-->
            <!--</div>-->
        </div>
    </div>
</template>
<script>
    export default {
        name:"pointcard-add",
        data(){
            const validateNum = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('请输入数字'));
                }
                // 模拟异步验证效果
                setTimeout(() => {
                    if (!Number.isInteger(value)) {
                        callback(new Error("请输入数字"));
                    } else {
                        callback();
                    }
                }, 1000);
            };
            return{
                title:"会员卡发放",
                formValidate:{
                    username:"",
                    phone:"",
                    num:"",
                    // shangji:"",
                    // tuanbei:"",
                    // dengji:"1",
                    level:"",
                    real_name:'',
                    birthday:'',
                },
                ruleValidate:{
                    username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                    sex: [{ required: true, message: '请选择性别', trigger: 'change' }],
                    phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
                    num: [{ required: true, message: '请输入数量', trigger: 'blur' }],
                    email: [{ required: true, message: '请输入电子邮箱', trigger: 'blur' }],
                    // shangji: [{ required: true, message: '请输入上级推手', trigger: 'blur' }],
                    // tuanbei: [{ required: true, validator: validateNum, trigger: 'blur' }],
                    level: [{ required: true, message: '请选择等级', trigger: 'change' }],
                    status: [{ required: true, message: '请选转状态', trigger: 'change' }],
                },
                imgUrl:"",
                loading:false,
                isEdit:false,
                uid:""
            }
        },
        mounted(){


        },
        methods:{
            getData(){


            },

            sub(){
                this.$refs.formValidate.validate((valid) => {
                    if (valid) {
                        this.sureSub()
                    }
                })
            },
            sureSub(){
                this.loading = true;

                this.getJsonData("Card/addCard",{
                    username:this.formValidate.username,
                    // phone:this.formValidate.phone,
                    num:this.formValidate.num,
                    type:this.formValidate.level,
                })
                    .then((res)=>{
                        this.loading = false
                        this.$Message.success(this.isEdit?'修改成功':'新增成功')
                        this.$router.back()
                    })
                    .catch((res)=>{
                        this.loading = false
                    })
            },
            reset(){
                this.imgUrl = ""
                this.$refs.formValidate.resetFields();
            }
        }
    }
</script>
<style lang="less">
    @import "./pointcard-add";
</style>